#include<stdio.h>
#include<string.h>
//i am from nanjing
//nanjing from an i

//逆序算法(首尾互换)
void Reserve(char *s,int len)
{
    for(int i=0; i<len/2;i++)
    {
        char temp=s[i];
        s[i]=s[len-1-i];
        s[len-i-1]=temp;
    }
}

void Reserve2(char *s,int len)
{
    int count=0;//单词长度
    for(int i=0;i<len;i++)
    {
        if(s[i] == ' ' || s[i]=='\0')
        {
            //单词逆序
            Reserve2(s+i-count,count);
            count=0;
        }
        else
        {
            count++;
        }
    }
}


int main()
{
    char str[]="i am from nanjing";
    Reserve(str,strlen(str));
    Reserve2(str,strlen(str));
    printf("%s\n",str);
    return 0;
}